package core;

import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;

public class Parser {

    public static void parse(String filename) {
        try {
            Scanner read = new Scanner(new File(filename));
            
            int factoryMoney = read.nextInt();
            int factoryWorkHour = read.nextInt();
            int maximumMachines= read.nextInt();
            int factoryRentableMachinesCount= read.nextInt();
            int truckCapacity= read.nextInt();                          
            
            Output.getInstance().println("Uang Awal : " + factoryMoney);
            Output.getInstance().println("Jam kerja pabrik : " + factoryWorkHour);
            Output.getInstance().println("Banyaknya jenis mesin yang ada yang dapat disewa : " + maximumMachines);
            Output.getInstance().println("Banyaknya jenis mesin yang dapat disewa oleh pabrik : " + factoryRentableMachinesCount);
            Output.getInstance().println("Kapasitas angkut truk : " + truckCapacity + " mesin");
            
            Factory.createInstance(factoryMoney, factoryWorkHour, maximumMachines, factoryRentableMachinesCount, truckCapacity);                  
            
            for(int i=0;i<maximumMachines;i++) {                             
                int type = i+1;                    
                int maxWorkHour = read.nextInt();
                int maxContinuedWorkHour = read.nextInt();
                int restTime = read.nextInt();
                int productivity = read.nextInt();
                int ingredientCount = read.nextInt();                
                int costOverload = read.nextInt();
                int rentCost = read.nextInt();
                int dependency = read.nextInt();                 
                
                Machine machine = new Machine(type, maxWorkHour, maxContinuedWorkHour, restTime, productivity, ingredientCount, costOverload, rentCost, dependency);                
                Factory.getInstance().addMachine(machine);                                
            }
                       
            Output.getInstance().println("");
            
            for(int i=0;i<9;i++) {
                for(int j=1;j<=Factory.getInstance().MAX_MACHINES;j++) {                                        
                    if(i==0 && j==1)
                        Output.getInstance().print("Mesin : \t");
                    else if(i==1 && j==1) 
                        Output.getInstance().print("T : \t\t");
                    else if(i==2 && j==1)
                        Output.getInstance().print("W : \t\t");
                    else if(i==3 && j==1)
                        Output.getInstance().print("S : \t\t");
                    else if(i==4 && j==1)
                        Output.getInstance().print("P : \t\t");
                    else if(i==5 && j==1)
                        Output.getInstance().print("I : \t\t");
                    else if(i==6 && j==1)
                        Output.getInstance().print("C : \t\t");
                    else if(i==7 && j==1) 
                        Output.getInstance().print("R : \t\t");
                    else if(i==8 && j==1)
                        Output.getInstance().print("Deskripsi : \t");                  
                    
                    if(i==0)       {                          
                        Output.getInstance().print(Factory.getInstance().getAllRentableMachines()[j-1].TYPE + "\t\t");
                    }else if(i==1)
                        Output.getInstance().print(Factory.getInstance().getAllRentableMachines()[j-1].MAX_WORK_HOUR + " jam \t\t");
                    else if(i==2)
                        Output.getInstance().print(Factory.getInstance().getAllRentableMachines()[j-1].MAX_CONTINUED_WORK_HOUR + " jam \t\t"); 
                    else if(i==3)
                        Output.getInstance().print(Factory.getInstance().getAllRentableMachines()[j-1].REST_TIME + " jam \t\t");
                    else if(i==4)
                        Output.getInstance().print(Factory.getInstance().getAllRentableMachines()[j-1].PRODUCTIVITY + " produk \t");
                    else if(i==5)
                        Output.getInstance().print((Factory.getInstance().getAllRentableMachines()[j-1].INGREDIENT_COUNT == 0 ? "- \t\t":Factory.getInstance().getAllRentableMachines()[j-1].INGREDIENT_COUNT+" produk \t"));
                    else if(i==6)
                        Output.getInstance().print(Factory.getInstance().getAllRentableMachines()[j-1].COST_OVERLOAD + "\t\t");
                    else if(i==7)
                        Output.getInstance().print(Factory.getInstance().getAllRentableMachines()[j-1].RENT_COST + "\t\t");
                    else if(i==8) {
                        if(Factory.getInstance().getAllRentableMachines()[j-1].DEPENDENCY == -1)
                            Output.getInstance().print("Independen\t");
                        else
                            Output.getInstance().print("Dependen " + Factory.getInstance().getAllRentableMachines()[j-1].DEPENDENCY+"\t");
                    }
                        
                    if(j==Factory.getInstance().MAX_MACHINES)
                        Output.getInstance().println("");
                }                    
            }
            
            int vendorCount = read.nextInt();
            for(int i=0;i<vendorCount;i++) {
                String name = read.next();
                int machinesForRentCount = read.nextInt();
                Vendor vendor = new Vendor(name, machinesForRentCount);
                VendorList.addVendor(vendor);
                for(int j=0;j<machinesForRentCount;j++) {                    
                    int machineType = read.nextInt();                  
                    vendor.addMachinesForRent(machineType);                    
                }                
            }
            
            Output.getInstance().println("");
            
            for(int i=0;i<VendorList.count();i++) {
                if(i==0) {
                    Output.getInstance().println("Vendor \t Nomor Mesin");
                }
                Output.getInstance().print(VendorList.getVendor(i).NAME + "\t");                
                for(int j=0;j<VendorList.getVendor(i).getAllMachinesForRent().size();j++) {
                    Output.getInstance().print(VendorList.getVendor(i).getAllMachinesForRent().get(j).TYPE + " ");
                }
                Output.getInstance().println("");
                
            }
            
            Output.getInstance().println("");
            
            for(int i=1;i<=maximumMachines;i++) {
                int type = i;
                int sellingPrice = read.nextInt();
                Product product = new Product(type, sellingPrice);
                ProductList.addProduct(product);
            }
            
            for(int i=1;i<=ProductList.count();i++) {
                if(i==1)
                    Output.getInstance().println("Produk \t Harga");
                
                Output.getInstance().println(ProductList.getProductByType(i).NAME + "\t" + ProductList.getProductByType(i).SELLING_PRICE);
            }
            
            Output.getInstance().println("");
            
            int row = read.nextInt();
            int col = read.nextInt();         
            char[][] map = new char[row][col];
            for(int i=0;i<row;i++) {
                String val = read.next();                
                for(int j=0;j<col;j++) {
                    map[i][j] = val.charAt(j);                    
                }
            }
            Map.createMap(row, col, map);
            
            Output.getInstance().println(Map.debugPrint());            
        }catch(FileNotFoundException e ){
            System.out.println("file tidak ditemukan");
        }        
    }           
    
}
